function DetailView() {
	var BookmarksDbHelper = require('ui/common/BookmarksDbHelper');
	var bookmarksDbHelper = new BookmarksDbHelper();

	var self = Ti.UI.createView();

	var data = [];
	
	self.setFirst = function(d) {
		data = d;
		data.lang = "mal";
		data.showBookmarkIcon = true;
		self.parent.title = data.title_ml;
		webview.url = '/content/ml/' + data.ml;
	};

	var webview = Titanium.UI.createWebView({
		backgroundColor : '#D3D3D3',
		setZoomScale : 2
	});

	self.add(webview);
	
	self.addEventListener('itemSelected', function(e) {
		data = {
			title_en : e.title_en,
			title_ml : e.title_ml,
			ml : e.ml,
			en : e.en,
			lang : e.lang,
			showBookmarkIcon: e.showBookmarkIcon
		};
		if (data.en) {
			self.parent.setRightNavButton(e.langButton);
		} else {
			self.parent.setRightNavButton(null);
		}

		if (data.en && data.lang == "eng") {
			e.langButton.title = "MAL";
			self.parent.title = data.title_en;
			webview.url = '/content/en/' + data.en;
		} else {
			e.langButton.title = "ENG";
			self.parent.title = data.title_ml;
			webview.url = '/content/ml/' + data.ml;
		}
	});

	self.addEventListener('langClicked', function(e) {
		if (data.lang == 'mal') {
			e.langButton.title = "MAL";
			self.parent.title = data.title_en;
			webview.url = '/content/en/' + data.en;
			data.lang = 'eng';
		} else {
			e.langButton.title = "ENG";
			self.parent.title = data.title_ml;
			webview.url = '/content/ml/' + data.ml;
			data.lang = 'mal';
		}
	});

	var minus = Titanium.UI.createButton({
	    image: 'minus.png'
	});
	
	var plus = Titanium.UI.createButton({
	    image: 'plus.png'
	});
	
	var share = Titanium.UI.createButton({
	    image: 'share.png'
	});
	
	var youtube = Titanium.UI.createButton({
	    image: 'youtube.png'
	});
	
	var flexSpace = Titanium.UI.createButton({
	    systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
	});

	var toolbar = Titanium.UI.iOS.createToolbar({
	    items:[minus, flexSpace, plus, flexSpace, share, flexSpace, youtube],
	    bottom:0,
	    borderTop:true,
	    borderBottom:false,
	    barColor: '#000',
	    opacity: 0.9
	});
	
	self.add(toolbar);
	
	minus.addEventListener("click", function(e) {
		webview.evalJS("resizeText(-1)");
	});
	
	plus.addEventListener("click", function(e) {
		webview.evalJS("resizeText(1)");
	});
	
	share.addEventListener("click", function(e) {
		var opts = {
			cancel : data.showBookmarkIcon ? 2 : 1,
			options : data.showBookmarkIcon ? ['Bookmark', 'Email', 'Cancel'] : ['Email', 'Cancel'],
			selectedIndex : data.showBookmarkIcon ? 2 : 1
		};
		var dialog = Ti.UI.createOptionDialog(opts);
		dialog.addEventListener("click", function(e) {
			var bindex = data.showBookmarkIcon ? 0 : -1;
			var eindex = data.showBookmarkIcon ? 1 : 0;
			
			if(e.index == bindex) {
				bookmarksDbHelper.insertRow(data);
			}
			else if(e.index == eindex) {
				var emailDialog = Ti.UI.createEmailDialog()
				emailDialog.subject = data.lang == "mal" ? data.title_ml : data.title_en;
				var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, data.lang == 'mal' ? '/content/ml/' + data.ml : '/content/en/' + data.en);
				var blob = f.read();
				emailDialog.setHtml(true);
				emailDialog.setMessageBody(blob.text);
				emailDialog.open();
				blob = null;
				f = null;
			}
		});
		dialog.show();
	});
	
	youtube.addEventListener("click", function(e) {
		self.fireEvent("youtubeClicked", data);
	});

	self.showShare = function(show) {
		if(show) {
			toolbar.setItems([minus, flexSpace, plus, flexSpace, share, flexSpace, youtube]);
		}
		else {
			toolbar.setItems([minus, flexSpace, plus]);
		}
	};

	return self;
};

module.exports = DetailView;
